#ifndef __VECTOR2_H
#define __VECTOR2_H

#include <iostream>
#include "defaultsetting.h"

class Vector2
{
  public:
    Vector2();
    Vector2(const REAL ax,const REAL ay);
    Vector2(const Vector2 &v);

    REAL getX()const;
    REAL getY()const;

    REAL getModule()const;
    REAL getAngle()const;

    void set(const REAL ax,const REAL ay);
    /**
      * Modify the coordinates using polar anotation
      */
    void setPolar(const REAL module,const REAL angle);
    void setX(const REAL ax);
    void setY(const REAL ay);

    /**
      * Modify the module without change the angle
      */
    void setModule(const REAL m);
    /**
      * Modify the angle without change the module
      */
    void setAngle(const REAL a);

    Vector2 operator+(const Vector2 &v)const;
    Vector2 operator-(const Vector2 &v)const;
    Vector2 operator*(const REAL k)const;
    bool operator==(const Vector2 &v)const;
    bool operator!=(const Vector2 &v)const;
    Vector2 operator-();

    friend std::ostream& operator<<(std::ostream& out,const Vector2& v);
    friend std::istream& operator>>(std::istream& in,Vector2& v);

  protected:

    REAL x;
    REAL y;
};

/**
  * Add vector a and b.
  * @returns A vector with the result of the operation.
  */
Vector2 add(const Vector2 &a,const Vector2 &b);

/**
  * Subtract vector a and b.
  * @returns A vector with the result of the operation.
  */
Vector2 sub(const Vector2 &a,const Vector2 &b);

/**
  * Makes the scalar product of vector a and b.
  * @returns The number the result of the operation.
  */
REAL dotProduct(const Vector2 &a,const Vector2 &b);

/**
  * Make the scalar product of vector v with the k number.
  * @returns A vector with the result of the operation.
  */
Vector2 multiply(const Vector2 &v,const REAL &k);

/**
  * Make the scalar product of vector v with the k number.
  * @returns A vector with the result of the operation.
  */
Vector2 multiply(const REAL &k,const Vector2 &v);

/**
  * @returns A vector with the same direction of v but with module is one.
  */
Vector2 normalize(const Vector2 &v);

/**
  * @returns A vector with v reflection over the n
  */
Vector2 reflect(const Vector2 &v,const Vector2 &n);

/**
  * @returns A vector with v's module but its opossite direction.
  */
Vector2 reverse(const Vector2 &v);

/**
  * @returns A vector with v's module but tis direction 90 degrees turned right.
  */
Vector2 rotateRight(const Vector2 &v);

/**
  * @returns A vector with v's module but tis direction 90 degrees turned right.
  */
Vector2 rotateLeft(const Vector2 &v);

#endif
